package net.chrisrichardson.cloudtools.maven.plugins;

import net.chrisrichardson.ec2deployer.cluster.ClusterManager;
import net.chrisrichardson.ec2deployer.cluster.SimpleCluster;

import org.apache.maven.plugin.MojoExecutionException;

public abstract class AbstractClusterMojo extends AbstractCloudToolsMojo {

  public AbstractClusterMojo() {
    super();
  }

  protected abstract void executeWithCluster(ClusterManager manager, SimpleCluster cluster);

  public void execute() throws MojoExecutionException {
  
    ClusterManager manager = makeClusterManager();
    // TODO - we should verify whether the specification of the cluster has
    // changed
    SimpleCluster cluster = (SimpleCluster) manager
        .getCluster(getClusterName());
  
    executeWithCluster(manager, cluster);
    
    postExecute(manager, cluster);
  
  }

  protected void postExecute(ClusterManager manager, SimpleCluster cluster) {
    // stub    
  }

}